#include <iostream>
#include <string>
using namespace std;

string convert(string s, int numRows) {
    if(numRows == 1) return s;
    int T = 2 * numRows - 2;
    string ans = "";
    for(int i=0;i<s.length();i+=T) ans += s[i];
    for(int i=1;i<numRows-1;i++){
        for(int j=i;j<s.length();j++){
            if(j % T == i || j%T == (T-i)) ans += s[j];
        }
    }
    for(int i=numRows-1;i<s.length();i+=T) ans += s[i];
    return ans;
}

int main(){
    string s= "PAYPALISHIRING";
    cout << convert(s, 4) << endl;
}